<?php

$show["NoTop"] = true;

session_cache_limiter('none');
include_once('common.php'); 


if($_GET["typDokumentu"] == 'predmet') {
$query = "SELECT
                    idSouboru,
                    filename,
                    origFilename,
                    prd_soubory.guid
            FROM
                    prd_soubory                    
            WHERE
                    idPredmetu = '".$_GET["idPredmetu"]."' AND
                    filename = '".$_GET["jmenoSouboru"]."' AND
                    guid = '".$_GET["guidSouboru"]."'
            ";
$row = $db->GetRow($query);

if(!empty($row)) {
    
    $reference = array();
    $reference[0] = $row["idSouboru"];
    $reference[1] = $row["filename"];
    
    aLog("soubory",$reference,4);

    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Pragma: public');
    header('Content-Length: ' . filesize('data/predmety/'.$row["filename"]));
    header('Content-Disposition: attachment; filename=' . basename($row["filename"]));
                                                                       
    ob_clean();
    flush();
    readfile($config["cesta"]["url"].'data/predmety/'.$row["filename"]);
    
    exit;
    
} else {
    e403();
    exit;
}


} else {
    e403();
    exit;
}  
?>